$(function(){
	initView();
	bindFun();
})
function initView(){
	//调用产品数据
		var params = {};
		params.age=Number(getQueryString("age"));
		var quoBase={};
		var quo=JSON.parse(sessionStorage.quoBase);
		quoBase.quoId=quo.quoId;
		quoBase.userIntId=quo.userIntId;
		quoBase.sign=quo.sign;
		params.quoBase=quoBase;
		padMarketing.ajaxNormal('/pad_marketing/main/quoGetPackages.action',params,	
		function(data) {
			//健康H  
			for(var i in data) {
				if(data[i].category=="H"){
					if(data[i].allowSaling==true){
						var pag1 = $("<li class='thumbnail'><img src='/portal/resources/images/product/packages/"+ data[i].pkgId  +"/ALL.jpg' alt='...'><div class='caption' data-app=\'"+JSON.stringify(data[i])+"\'><h3 class='font-16 p-overflow'>" + data[i].title + "</h3><p class='font-14 gray'>" + data[i].subTitle + "</p></div><div class='check-list default'><input data-app ='"+JSON.stringify(data[i])+"' type='checkbox'><label for=''>&nbsp;</label></div></li>");					
					}
					else{
						var pag1 = $("<li class='thumbnail'><img src='/portal/resources/images/product/packages/"+ data[i].pkgId  +"/ALL.jpg' alt='...'><div class='caption' data-app=\'"+JSON.stringify(data[i])+"\'><h3 class='font-16 p-overflow'>" + data[i].title + "</h3><p class='font-14 gray'>" + data[i].subTitle + "</p></div><div class='check-list default disabled'><input disabled data-app ='"+JSON.stringify(data[i])+"' type='checkbox'><label for=''>&nbsp;</label></div></li>");
					}
				}
				$('#health').append(pag1);
			}
			//退休R
			for(var j in data) {
				if(data[j].category=="R"){
					if(data[j].allowSaling==true){
						var pag2 = $("<li class='thumbnail'><img src='/portal/resources/images/product/packages/"+ data[j].pkgId  +"/ALL.jpg' alt='...'><div class='caption' data-app=\'"+JSON.stringify(data[j])+"\'><h3 class='font-16 p-overflow'>" + data[j].title + "</h3><p class='font-14 gray'>" + data[j].subTitle + "</p></div><div class='check-list default'><input data-app ='"+JSON.stringify(data[j])+"' type='checkbox'><label for=''>&nbsp;</label></div></li>");					
					}
					else{
						var pag2 = $("<li class='thumbnail'><img src='/portal/resources/images/product/packages/"+ data[j].pkgId  +"/ALL.jpg' alt='...'><div class='caption' data-app=\'"+JSON.stringify(data[j])+"\'><h3 class='font-16 p-overflow'>" + data[j].title + "</h3><p class='font-14 gray'>" + data[j].subTitle + "</p></div><div class='check-list default disabled'><input disabled data-app ='"+JSON.stringify(data[j])+"' type='checkbox'><label for=''>&nbsp;</label></div></li>");
					}
				}
				$('#old').append(pag2);
	
			}
			//子女教育E
			for (var k in data) {
				if(data[k].category=="E"){
					if(data[k].allowSaling==true){
						var pag3 = $("<li class='thumbnail'><img src='/portal/resources/images/product/packages/"+ data[k].pkgId  +"/ALL.jpg' alt='...'><div class='caption' data-app=\'"+JSON.stringify(data[k])+"\'><h3 class='font-16 p-overflow'>" + data[k].title + "</h3><p class='font-14 gray'>" + data[k].subTitle + "</p></div><div class='check-list default'><input data-app ='"+JSON.stringify(data[k])+"' type='checkbox'><label for=''>&nbsp;</label></div></li>");					
					}
					else{
						var pag3 = $("<li class='thumbnail'><img src='/portal/resources/images/product/packages/"+ data[k].pkgId  +"/ALL.jpg' alt='...'><div class='caption' data-app=\'"+JSON.stringify(data[k])+"\'><h3 class='font-16 p-overflow'>" + data[k].title + "</h3><p class='font-14 gray'>" + data[k].subTitle + "</p></div><div class='check-list default disabled'><input disabled data-app ='"+JSON.stringify(data[k])+"' type='checkbox'><label for=''>&nbsp;</label></div></li>");
					}
				}
				$('#edu').append(pag3);
			}
			//財富F
	      	for (var l in data) {
	      		if(data[l].category=="F"){
					if(data[l].allowSaling==true){
						var pag5 = $("<li class='thumbnail'><img src='/portal/resources/images/product/packages/"+ data[l].pkgId  +"/ALL.jpg' alt='...'><div class='caption' data-app=\'"+JSON.stringify(data[l])+"\'><h3 class='font-16 p-overflow'>" + data[l].title + "</h3><p class='font-14 gray'>" + data[l].subTitle + "</p></div><div class='check-list default'><input data-app ='"+JSON.stringify(data[l])+"' type='checkbox'><label for=''>&nbsp;</label></div></li>");					
					}
					else{
						var pag5 = $("<li class='thumbnail'><img src='/portal/resources/images/product/packages/"+ data[l].pkgId  +"/ALL.jpg' alt='...'><div class='caption' data-app=\'"+JSON.stringify(data[l])+"\'><h3 class='font-16 p-overflow'>" + data[l].title + "</h3><p class='font-14 gray'>" + data[l].subTitle + "</p></div><div class='check-list default disabled'><input disabled data-app ='"+JSON.stringify(data[l])+"' type='checkbox'><label for=''>&nbsp;</label></div></li>");
					}
				}$('#plan').append(pag5);
			}
			//旅遊L
			for (var m in data) {
				if(data[m].category=="L"){
					if(data[m].allowSaling==true){
						var pag4 = $("<li class='thumbnail'><img src='/portal/resources/images/product/packages/"+ data[m].pkgId  +"/ALL.jpg' alt='...'><div class='caption' data-app=\'"+JSON.stringify(data[m])+"\'><h3 class='font-16 p-overflow'>" + data[m].title + "</h3><p class='font-14 gray'>" + data[m].subTitle + "</p></div><div class='check-list default'><input data-app ='"+JSON.stringify(data[m])+"' type='checkbox'><label for=''>&nbsp;</label></div></li>");					
					}
					else{
						var pag4 = $("<li class='thumbnail'><img src='/portal/resources/images/product/packages/"+ data[m].pkgId  +"/ALL.jpg' alt='...'><div class='caption' data-app=\'"+JSON.stringify(data[m])+"\'><h3 class='font-16 p-overflow'>" + data[m].title + "</h3><p class='font-14 gray'>" + data[m].subTitle + "</p></div><div class='check-list default disabled'><input disabled data-app ='"+JSON.stringify(data[m])+"' type='checkbox'><label for=''>&nbsp;</label></div></li>");
					}
				}
				$('#life').append(pag4);
			}			
		},
		function(){
			
		}
	);
}
function bindFun(){
	$("#return").click(function(){
		location.href = '/pad_marketing/plan/proposalNew.action';
	});
	$("#returnBack").click(function(){
		location.href = '/pad_marketing/plan/proposalNew.action';
	});
	$("#complete").click(function(){
		//获取选中的产品
		var idArr =[];		
		$(".check-list  input:checkbox:checked").each(function(){
			idArr.push(JSON.parse($(this).attr("data-app")));
		});	
		
		if(idArr.length==0)
		{
			alertMsg("请您选择产品,若不添加主险,请您返回上页");
			return;
		}
		
		var params={};
		
		//测试数据
		params ={"quoBase":{"quoId":2611743,"sign":"511E8A187D49295DE3015A6621BC61C0"},
				"pkgs":[{"pkgId":113,"sign":"E657BCC950F3B75D11533FC1FC975A1B"}], 
				"ins":{"cpId":3, "age":15, "sex":"F", "ocCode":"A01", "name":"张三"}};
		if(sessionStorage.quoBase)
			params.quoBase = JSON.parse(sessionStorage.quoBase);
		if(sessionStorage.ins)
			params.ins = JSON.parse(sessionStorage.ins);
		params.pkgs = idArr;
		
		padMarketing.ajaxNormal(
				'/pad_marketing/main/quoAddProducts.action', //请求地址
				params,
				function(data){
					
					location.href = '/pad_marketing/plan/proposalNew.action';
				},
				function(data){
					console.log(data);
				}
			);
		
	});	
}

$(document).on('click','.thumbnail',function(){
	$(".tabs-line a").eq(0).addClass("active").siblings().removeClass("active");
	$("#open4 .tabSwiper .swiper-wrapper .swiper-slide").eq(0).addClass("swiper-slide-active").siblings().removeClass("swiper-slide-active");
	$("#open4 .tabSwiper .swiper-wrapper").css({"transform":" translate3d(0px, 0px, 0px)","transition-duration": "0 s"});
	var ob = JSON.parse($(this).find('.caption').attr("data-app"));	
	var params = {};
	params.pkgId = ob.pkgId;
	params.sign = ob.sign;
	padMarketing.ajaxNormal(
		'/pad_marketing/main/type003getDecall.action',
		params,
		function(data){
			
			$("#title").html(data.title+" (投保年龄："+data.subTitle+")");
			/*$("#subTitle").html(data.subTitle);*/
			$("#benefit").html(data.benefit);
			$("#feature").html(data.feature);
			$("#featureimg").attr("src","/portal/resources/images/product/packages/"+ data.pkgId +"/CPTS.jpg");
			$("#benefitimg").attr("src","/portal/resources/images/product/packages/"+ data.pkgId +"/LYJJ.jpg");
			$("#demoImg").attr("src","/portal/resources/images/product/packages/"+ data.pkgId +"/TBSL.jpg");
		},
		function(data){
			console.log('fail');
		}		
	);
	showDiv('open4');
})
$(document).on('click','.check-list',function(event){
	 event.stopPropagation();
})

$(document).on('click','input',function(){
	var slide = $(".check-list  input:checkbox:checked").attr('data-app');		
	var obj = JSON.parse(slide);
	if(obj.allowSaling){		
		
	}else{
		$(".check-list  input").attr('info','1');
		alertMsg('此产品不可购买');
			$('#alertMsg_btn3').click(function(){
				$('input[info="1"]').prop("checked",false);
			})		
	}
})
